//
//  ExchangeViewController.m
//  UI_豆瓣2.0
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ExchangeViewController.h"
#import "MovieListViewController.h"
#import "MovieNineViewController.h"

@interface ExchangeViewController ()

@property (nonatomic, retain)UIImage *listRightImage;
@property (nonatomic, retain)UIImage *nineRightImage;
@property (nonatomic, retain)MovieListViewController *movieListVC;
@property (nonatomic, retain)MovieNineViewController *movieNienVC;
@property (nonatomic, assign)BOOL isSelected;

@end

@implementation ExchangeViewController

- (void)dealloc
{
    [_listRightImage release];
    [_nineRightImage release];
    [_movieListVC release];
    [_movieNienVC release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"电影";
    
#pragma mark -- 取消图片渲染
    self.listRightImage = [UIImage imageNamed:@"btn_nav_collection@2x.png"];
    self.listRightImage = [self.listRightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.nineRightImage = [UIImage imageNamed:@"btn_nav_list@2x.png"];
    self.nineRightImage = [self.nineRightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
#pragma mark -- 自定义创建按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 20, 20);
    [button setImage:self.listRightImage forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
#pragma mark -- 容器视图控制器
    // 就是一个viewController上面放了两个或者多个viewController切换子类控制器
    self.movieNienVC = [[MovieNineViewController alloc] init];
    [self addChildViewController:self.movieNienVC];
    [self.view addSubview:self.movieNienVC.view];
    self.movieListVC = [[MovieListViewController alloc] init];
    [self addChildViewController:self.movieListVC];
    [self.view addSubview:self.movieListVC.view];
    
    [_movieNienVC release];
    [_movieListVC release];
    
    
    self.isSelected = NO;
   
}

- (void)buttonAction:(UIButton *)button{
    
    if (YES != self.isSelected) {
        [UIView transitionFromView:self.movieListVC.view toView:self.movieNienVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
            
            
        }];
        [button setImage:self.nineRightImage forState:UIControlStateNormal];
    } else {
        [UIView transitionFromView:self.movieNienVC.view toView:self.movieListVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
            
            
        }];
        [button setImage:self.listRightImage forState:UIControlStateNormal];
    }
    self.isSelected = !self.isSelected;
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
